
#include<iostream>
using namespace std;

int
main ()
{
  int t, a;
  cin >> t;
  a = t;
  if (t < 10000 && t > 999)
	{
	  int f[10];
	  for (int i = 0; i < 4; i++)
		{
		  f[i] = a % 10;
		  a = a / 10;
		}
	  a = t;
	  for (int i = 4; i < 7; i++)
		{
		  f[i] = a % 100;
		  a = a / 10;
		}
	  a = t;
	  for (int i = 7; i < 9; i++)
		{
		  f[i] = a % 1000;
		  a = a / 10;
		}
	  a = t;
	  f[9] = t;
	  int g[10] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
	  for (int i = 0; i < 10; i++)
		{
		  int k = f[i], l = 0;
		  for (int j = 1; j < k + 1; j++)
			{
			  if (k % j == 0)
				{
				  l++;
				}
			}
		  if (l == 2)
			{
			  g[i] = k;
			}
		}
	  int max = 0;
	  for (int i = 0; i < 10; i++)
		{
		  if (max < g[i])
			{
			  max = g[i];
			}
		}
	  cout << max;
	}
  else
	{
	  cout << 0;
	}
  return 0;
}
